package me.xplabs.role 
{
	import flash.display.BitmapData;
	import flash.utils.Dictionary;
	import me.xplabs.engine.display.BaseAnimate;
	import me.xplabs.engine.display.BaseDisplay;
	import me.xplabs.model.combatunit.MRoleInfo;
	import me.xplabs.utils.Utils;
	
	/**
	 * 游戏的角色npc
	 * ...
	 * @author xiaohan
	 */
	public class RoleDisplay extends BaseAnimate 
	{
		public var roleInfo:MRoleInfo;
		public var resLib:Dictionary;
		private var _prevStatus:int;
		private var _curStatus:int;
		
		private var _healthWidth:int;
		private var _healthBars:BaseDisplay;
		private var _liftBars:BaseDisplay;
		public function RoleDisplay() 
		{
			super();
			_healthWidth = 15;
			resLib = new Dictionary();
			init();
		}
		public function init():void
		{
			
			_liftBars = new BaseDisplay();
			_liftBars.data = new BitmapData(_healthWidth, 2, true, 0xFFF93C40);
			_liftBars.mouseEnable = false;
			addChild(_liftBars);
			
			_healthBars = new BaseDisplay();
			_healthBars.data = new BitmapData(_healthWidth, 2, true, 0xFF32DC54);
			_healthBars.mouseEnable = false;
			//_healthBars.rotation = 3;
			addChild(_healthBars);
		}
		override public function update(container:BitmapData):void 
		{
			if (roleInfo)
			{
				x = roleInfo.curPosX;
				y = roleInfo.curPosY;
				changeStatus(Utils.directionStatus(roleInfo.angle));
				_healthBars.width = (roleInfo.curLife / roleInfo.life) * _healthWidth;
				if (_healthBars.width <= 1) _healthBars.width = 1;
				//changeStatus(1);
			}
			if (data)
			{
				_healthBars.x = data.width * .5 - _healthWidth * .5;
				_liftBars.x = data.width * .5 - _healthWidth * .5;
			}
			super.update(container);
		}
		private function changeStatus(status:int):void
		{
			_curStatus = status;
			if (_prevStatus == _curStatus || !resLib) return;
			sequence = resLib[_curStatus];
			_prevStatus = _curStatus;
		}
		
		override public function dispose():void 
		{
			super.dispose();
			_prevStatus = 0;
			_curStatus = 0;
			roleInfo = null;
			for (var name:String in resLib) 
			{
				delete resLib[name];
			}
		}
	}
}